package comviva_2014.SmartMapper;


public class PackTest {
	
	public static void main(String[] args) {
		
		int initialCapacity = 30000000;
		int capacity = 1;
			while (capacity < initialCapacity)
			capacity <<= 1;

		System.out.println("Capacity: " + capacity);
		
		byte[] input = "00000000000000166966920433921".getBytes();
		byte[] packed = pack(input);
		byte[] unpack = unPack(packed);
		System.out.println(new String(unpack));
		
		int in = 176;
		System.out.println((in << 5) - in );

		
	}
	
	private static byte[] pack(byte[] in) {
		byte[] pack = new byte[15];

		int j = 0;
		int i = 0;
		System.out.println("in length: " + in.length);
		for (; i < in.length - 1; i += 2) {
			System.out.printf("i = %d, i+1 = %d\n", i, i+1);
			pack[j++] = (byte) ( (in[i] - '0') << 4 | (0x0F & (in[i + 1] - '0')));
		}
		pack[j] = (byte) ((in[i] - '0') << 4);
		return pack;
	}
	
	private static byte[] unPack(byte[] in) {
		byte[] unpack = new byte[29];

		System.out.println(in.length);
		int p = 0;
		int i = 0;
		for (; i < in.length -1; i++) {
			unpack[p] = (byte) ((in[i] & 0xF0) >> 4);
			unpack[p + 1] = (byte) (in[i] & 0x0F);
			
			unpack[p] += '0';
			unpack[p+1] += '0';
			p += 2;
		}
		unpack[p] = (byte) (((in[i] & 0xF0) >> 4) + '0');

		return unpack;
	}

}
